﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TonyNet4V1.Control
{
	
	public class ITemplateModifyDelete : ITemplate
	{
		private string strColumnName;
		private DataControlRowType dcrtColumnType;

		public string strModifyText;
		public string strModifyCommandName;
		public string strModifyCommandArgument;

		public string strDeleteText;
		public string strDeleteCommandName;
		public string strDeleteCommandArgument;
		public string strDeleteConfirm;

		public ITemplateModifyDelete()
		{
			strModifyText = "修改";
			strModifyCommandName = "Edit";
			strModifyCommandArgument = "";

			strDeleteText = "删除";
			strDeleteCommandName = "Delete";
			strDeleteCommandArgument = "";

			strDeleteConfirm = "确认要删除吗？";
		}

		public ITemplateModifyDelete(DataControlRowType dcrtType)
			: this()
		{
			this.dcrtColumnType = dcrtType;
		}

		public ITemplateModifyDelete(string strColumnName, DataControlRowType dcrtType)
			: this()
		{
			this.strColumnName = strColumnName;
			this.dcrtColumnType = dcrtType;
		}

		public void InstantiateIn(System.Web.UI.Control ctlContainer)
		{
			switch (dcrtColumnType)
			{
				case DataControlRowType.Header:
					Literal ltr = new Literal();
					ltr.Text = strColumnName;
					ctlContainer.Controls.Add(ltr);
					break;
				case DataControlRowType.DataRow:

					LinkButton linkButtonModify = new LinkButton();
					LinkButton linkButtonDelete = new LinkButton();

					linkButtonModify.Text = strModifyText;
					linkButtonModify.CommandName = strModifyCommandName;
					linkButtonModify.CommandArgument = strModifyCommandArgument;
					linkButtonDelete.Text = strDeleteText;
					linkButtonDelete.CommandName = strDeleteCommandName;
					linkButtonDelete.OnClientClick = "javascript:return confirm('"+strDeleteConfirm+"')";

					ctlContainer.Controls.Add(linkButtonModify);
					ctlContainer.Controls.Add(linkButtonDelete);
					break;

			}
		}
	}
}